using System;

namespace SharpMud.MudLib.SAMPLE.Net.SessionStates
{
	public class Quit : SessionStateBase
	{
		public Quit()
		{
		}
		public override string StateID
		{
			get
			{
				return "Quit";
			}
		}
		public override void Pulse()
		{
			if(StillActive)
			{
				MudLib.SAMPLE.Environment.Room r = MudServer.EnvironmentSystem.GetRoom(Session.CurrentCharacter.Location);
				//Remove the player from the world
				r.DeregisterCharacterFromHere(Session.CurrentCharacter);
				//Tell the player system that the player has been removed from the world
				MudServer.PlayerSystem.RegisterPlayerNotPlaying(Session.CurrentCharacter);
				
				Session.Logoff();
				
				Session.SessionState.Clear();
				this.SetInactive();
				this.Session.Connection.Close();
				

				//No notification messages are sent to the player regarding the Quit. It may
				//be neccesary to cause the player to quit without telling the player. It is the
				//responsibility of the code that initiates the Quit, (such as the Quit command),
				//to tell the player what is happening.
			}
		}
	}
}